//
// Created by Semir on 2020/4/26.
//

#include <iostream>
#include <algorithm>

using namespace std;

const int MAX_N = 10005;
int n;
int arr[MAX_N];

bool cmp(int a, int b) {
    return a > b;
}

/**
 * 使用sort 整个数组频繁sort 效率较低 部分case超时
 * @return
 */
int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    sort(arr, arr + n, cmp);
    long long cost = 0;
    int len = n;
    while (len > 1) {
        int curSum = arr[len - 1] + arr[len - 2];
        cost += curSum;
        arr[len - 2] = curSum;
        len--;
        sort(arr, arr + len, cmp);
    }
    cout << cost << endl;
    return 0;
}